package com.publicize.service.impl;

import com.publicize.commom.servicebase.exception.MyException;
import com.publicize.entity.ModulePicture;
import com.publicize.mapper.ModulePictureMapper;
import com.publicize.service.ModulePictureService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.publicize.service.OssService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 投稿图片表 服务实现类
 * </p>
 *
 * @author bs
 * @since 2021-03-10
 */
@Service
public class ModulePictureServiceImpl extends ServiceImpl<ModulePictureMapper, ModulePicture> implements ModulePictureService {
    @Resource
    private OssService ossService;
    @Override
    public List<String> addPicture(MultipartFile[] file) {
        if(file.length>3) throw new MyException("图片不能超过三张",201);
        List<String> urls=new ArrayList<>();
        for(MultipartFile multipartFile:file){
            String url = ossService.uploadFileAvatar(multipartFile);
            urls.add(url);
        }
        return urls;
    }
}
